<template>
    <div class="main">
        <div style="width: 100%;height: 40px;background-color: #fff;margin-bottom: 20px;padding: 10px;">当前模块:<span
                style="font-weight: bold;">设置本校区教师的任教学科 (教师教的课程) </span> </div>
        <div class="main-body">
            <el-row>
                <el-col :span="14">
                    <div class="main-header float-left">

                        <el-form :inline="true" :model="formInline" class="demo-form-inline" size="mini">

                            <el-form-item label="筛选条件：">
                                <el-input v-model="formInline.xm" placeholder="请输入" clearable></el-input>
                            </el-form-item>


                            <el-form-item>
                                <el-button type="primary" @click="onSubmit" icon="el-icon-search">查询</el-button>
                                <el-button type="primary" icon="el-icon-plus" @click="addJzgxk">新增学科任教教师</el-button>
                            </el-form-item>
                        </el-form>

                    </div>
                    <div class="main-center float-left">
                        <el-table
                            :data="tableData.slice((formInline.currentPage - 1) * formInline.limit, formInline.currentPage * formInline.limit)"
                            height="650" style="width: 100%;margin-top: 6px;"
                            :header-cell-style="{ background: '#fafafa', color: '#000000e0', fontWeight: 600 }">
                            <el-table-column prop="XM" label="姓名"></el-table-column>
                            <el-table-column prop="XB" label="性别"></el-table-column>
                            <el-table-column prop="kcm" label="任教学科"></el-table-column>
                            <el-table-column prop="GWZT" label="岗位状态"></el-table-column>
                            <el-table-column label="管理操作" width="200">
                                <template slot-scope="scope" style="z-index: -9999;">
                                    <el-button @click="handleEdit(scope.row)" type="text" size="small"
                                        style="color: #ff4d4f;" icon="el-icon-edit">编辑</el-button>
                                    <el-button @click="handleDelete(scope.row)" type="text" size="small"
                                        style="color: #ff4d4f;" icon="el-icon-delete">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>

                        <div class="footer-pagination">
                            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                :current-page="formInline.currentPage"
                                :page-sizes="[10, 20, 30, 50, 100, 200, 300, 500]" :page-size="formInline.limit"
                                layout="total, sizes, prev, pager, next, jumper" :total="formInline.total">
                            </el-pagination>
                        </div>
                    </div>
                </el-col>
                <el-col :span="8" style="margin-left: 40px;">
                    <div class="main-header float-left">
                        <div style="text-align: center;">本校区教职工中，没有设置任教学科的名单</div>
                    </div>
                    <div class="main-center float-left" style="margin-top: 25px;">
                        <el-table :data="tableData2" height="650" style="width: 100%;margin-top: 6px;"
                            :header-cell-style="{ background: '#fafafa', color: '#000000e0', fontWeight: 600 }">
                            <el-table-column prop="XM" label="姓名"></el-table-column>
                            <el-table-column prop="XB" label="性别"></el-table-column>

                            <el-table-column prop="GWZT" label="岗位状态"></el-table-column>

                        </el-table>

                        <!-- <div class="footer-pagination">
                            <el-pagination @size-change="handleSizeChange2" @current-change="handleCurrentChange2"
                                :current-page="formInline2.currentPage"
                                :page-sizes="[10, 20, 30, 50, 100, 200, 300, 500]" :page-size="formInline2.limit"
                                layout="total, sizes, prev, pager, next, jumper" :total="formInline2.total">
                            </el-pagination>
                        </div> -->
                    </div>
                </el-col>
            </el-row>


            <el-dialog title="学科的任课教师设置操作窗口" :visible.sync="dialogDetails" width="40%">
                <div>
                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px" class="demo-ruleForm">

                        <el-form-item label="选择设置的学科:" prop="xk">
                            <el-select v-model="ruleForm.xk" placeholder="请选择">
                                <el-option v-for="(item, index) in xklist" :key="index" :label="item.MC"
                                    :value="item.DM">
                                </el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item label="选择承担学科教学任务的教师" prop="type">

                           <el-select  v-model="ruleForm.type" placeholder="请选择">
                            <el-option v-for="(item, index) in tableData2" :key="index" :label="item.TeacherId"
                                    name="type">
                                <el-checkbox>{{item.XM}}</el-checkbox>
                        </el-option>
                            
                            </el-select>

                        </el-form-item>

                        <el-form-item>
                            <el-button type="primary" @click="submitForm('ruleForm')">提 交</el-button>
                            <el-button @click="dialogDetails = false">取 消</el-button>
                        </el-form-item>
                    </el-form>
                </div>
                <!-- <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogDetails = false">取 消</el-button>
                    <el-button type="primary" @click="dialogDetails = false">提 交</el-button>
                </span> -->
            </el-dialog>

            <el-dialog title="教师任教学科的设置操作窗口" :visible.sync="dialogDetails2" width="40%">
                <div>
                    <div>请选择[{{ title }}]任教的学科</div>
                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px" class="demo-ruleForm">



                        <el-form-item label="" prop="type">
                            <el-checkbox-group v-model="ruleForm.type2">
                                <el-checkbox v-for="(item, index) in xklist" :key="index" :label="item.DM"
                                    name="type">{{ item.MC
                                    }}</el-checkbox>

                            </el-checkbox-group>
                        </el-form-item>

                        <el-form-item>
                            <el-button type="primary" @click="submitForm2('ruleForm')">提 交</el-button>
                            <el-button @click="dialogDetails = false">取 消</el-button>
                        </el-form-item>
                    </el-form>
                </div>
                <!-- <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogDetails = false">取 消</el-button>
                    <el-button type="primary" @click="dialogDetails = false">提 交</el-button>
                </span> -->
            </el-dialog>


        </div>
    </div>
</template>
<script>
import httplogin from "../../api/login";
export default {
    name: 'Social',
    data() {
        return {
            printOption: {
                id: 'nbprint', // 打印元素的id 不需要携带#号
                popTitle: '教职工基本信息登记表' // 页眉标题 默认浏览器标题 空字符串时显示undefined 使用html语言
            },
            ruleForm: {
                xk: '',

                type: [],
                type2: [],

            },
            tableData: [],
            tableData2: [],
            formInline: {
                xq: "",
                nj: '',
                xm: '',
                ddl_xz: '',
                ddl_jdfs: '',
                currentPage: 1,
                limit: 10,
                total: 0
            },
            formInline2: {
                xq: "",
                nj: '',
                xm: '',
                ddl_xz: '',
                ddl_jdfs: '',
                currentPage: 1,
                limit: 10,
                total: 0
            },
            ddl_lb_list: [

            ],//类别 options
            ddl_bb_list: [],//办别 options
            ddl_xz_list: [
                {
                    value: '全部',
                    label: '全部'
                },
                {
                    value: '普通',
                    label: '普通'
                },
                {
                    value: '工读',
                    label: '工读'
                },
                {
                    value: '特教',
                    label: '特教'
                },
            ],//性质 options
            ddl_jdfs_list: [
                {
                    value: '全部',
                    label: '全部'
                },
                {
                    value: '走读',
                    label: '走读'
                },
                {
                    value: '寄宿',
                    label: '寄宿'
                },
            ],//就读方式 options
            dialogDetails: false,
            dialogDetails2: false,
            JiaoZhiGongInfo: {},
            schoolList: [],
            xklist: [],
            title: "",
            TeacherId: ""

        }
    },
    mounted() {
        this.getTeacherSubjectway()
        this.getTeacherSubjectway2()
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    var data = {
                        mqzjxk: "/" + this.ruleForm.xk + "/",
                        teacherIds: this.ruleForm.type,

                    }
                    httplogin.updateFaculty(data).then(res => {
                        if (res.data.code == 200) {
                            this.$message.success(res.data.msg, 3);
                            this.dialogDetails = false
                            this.getTeacherSubjectway()
                            this.getTeacherSubjectway2()
                        }
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        submitForm2(formName) {
            var arr = []
            arr.push(this.TeacherId)
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    let result = this.ruleForm.type2.join("/")
                    var data = {
                        mqzjxk: result,
                        teacherIds: arr

                    }
                    httplogin.updateFaculty(data).then(res => {
                        if (res.data.code == 200) {
                            this.$message.success(res.data.msg, 3);
                            this.dialogDetails2 = false
                            this.getTeacherSubjectway()
                            this.getTeacherSubjectway2()
                        }
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        async getAllDistListway() {
            var res = await httplogin.getAllDistList();
            if (res.data.code == 200) {
                this.xklist = res.data.data.data.dm_xk
                this.ruleForm.xk = this.xklist[0].DM

            }
        },
        async getTeacherSubjectway() {
            let data = {
                xm: this.formInline.xm,
                page: this.formInline.currentPage,
                size: this.formInline.limit,
                rj: "1"
            }
            let res = await httplogin.getTeacherSubject(data);
            if (res.data.code == 200) {
                this.tableData = res.data.data.list;
                this.formInline.total = res.data.data.list.length
            }
        },
        async getTeacherSubjectway2() {
            let data = {
                xm: this.formInline2.xm,
                page: this.formInline2.currentPage,
                size: this.formInline2.limit,
                rj: "0"
            }
            let res = await httplogin.getTeacherSubject(data);
            if (res.data.code == 200) {
                this.tableData2 = res.data.data.list;
                // this.formInline2.total = res.data.data.list.length
            }
        },
        addJzgxk() {
            this.getAllDistListway();
            this.dialogDetails = true
        },
        handleDelete(row) {
            var arr=[]
            arr.push(row.TeacherId)
            var data = {
                mqzjxk: "",
                teacherIds: arr,
              

            }
            httplogin.updateFaculty(data).then(res => {
                if (res.data.code == 200) {
                    this.$message.success(res.data.msg, 3);

                    this.getTeacherSubjectway()
                    this.getTeacherSubjectway2()
                }
            })
        },

        //getGrade

        getNowTimeDate() {
            const now = new Date();
            const year = now.getFullYear();
            const month = ('0' + (now.getMonth() + 1)).slice(-2);
            const day = ('0' + now.getDate()).slice(-2);
            // const hours = ('0' + now.getHours()).slice(-2);
            // const minutes = ('0' + now.getMinutes()).slice(-2);
            // const seconds = ('0' + now.getSeconds()).slice(-2);
            const formattedTime = year + "年" + month + "月" + day + "日"
            return formattedTime
        },
        sortPingyinfun(list) {
            list.sort((a, b) => a.XQJC.localeCompare(b.XQJC))
            return list
        },
        //点击查看详情 open 弹框
        handleClick(row) {
            this.getOnGuardFacultyInfoway(row)
            this.dialogDetails = true
        },
        async getOnGuardFacultyInfoway(val) {
            var data = {
                jzgId: val.TeacherID
            }
            var res = await httplogin.getOnGuardFacultyInfo(data)
            if (res.data.code == 200) {
                this.JiaoZhiGongInfo = res.data.data.jzgInfo

            }
        },
        handleEdit(row) {

            this.title = row.XM;
            this.TeacherId = row.TeacherId;
            this.getAllDistListway();
            this.dialogDetails2 = true
        },
        //close 弹框
        handleClose() {
            this.dialogDetails = false
        },
        onSubmit() {
            this.getTeacherSubjectway()
            // console.log(this.formInline);
        },
        handleSizeChange(val) {
            this.formInline.limit = val
            this.getTeacherSubjectway()
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.formInline.currentPage = val
            this.getTeacherSubjectway()
            console.log(`当前页: ${val}`);
        },
        handleSizeChange2(val) {
            this.formInline2.limit = val
            this.getTeacherSubjectway2()
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange2(val) {
            this.formInline2.currentPage = val
            this.getTeacherSubjectway2()
            console.log(`当前页: ${val}`);
        }
    }
}
</script>

<style scoped>
.main {
    width: 100%;
    float: left;
    height: auto;
    box-sizing: border-box;
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #f6f6f6;
    overflow-x: auto;
    overflow-y: auto;
}

.main-body {
    width: 100%;
    height: auto;
    float: left;
    background-color: #fff;
    box-sizing: border-box;
    padding: 18px;
    border-radius: 12px;
}

.float-left {
    width: 100%;
    height: auto;
    float: left;
}

.main-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.d-flex {
    display: flex;
    align-items: center;
}

.mr-24 {
    margin-right: 24px;
}

.fontcolor {
    color: rgba(0, 0, 0, 0.88);
    word-break: break-word;
    line-height: 1.5714285714285714;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
    font-size: 14px;
    box-sizing: border-box;
}

.footer-pagination {
    padding: 10px 0 0 0;
    text-align: right;
}

.font-all {
    color: rgba(0, 0, 0, 0.88);
    font-size: 14px;
    line-height: 1.5714285714285714;
    list-style: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
    scrollbar-color: rgba(0, 0, 0, 0.25) rgba(5, 5, 5, 0.06);
}
</style>

<style scoped>
::v-deep .el-dialog {
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    position: absolute;
    top: 44%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: calc(100% - 30px);
    max-width: calc(100% - 30px);
}

::v-deep .el-dialog .el-dialog__body {
    flex: 1;
    overflow: auto;
}

::v-deep .el-dialog__header {
    background-color: #ff4d4f !important;

}

::v-deep .el-dialog__title {
    line-height: 24px;
    font-size: 20px;
    color: #fff !important;
    /* font-weight: 600; */
}
</style>